package com.example.hello.controller;

import freemarker.template.utility.StringUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

@Controller
public class LoginController {
    /*@GetMapping("/login")
    public String loginhtml(){
        return "login";
    }*/
    @PostMapping("/logincheck")
    @ResponseBody
    public String login(@RequestParam("username") String username, @RequestParam("password") String password,
                        HttpSession session){
        if (username==null || username.equals("")){
            return "用户名不能为空";
        }else if (password==null || password.equals("")){
            return "密码不能为空";
        }else if(!password.equals("123456")){
            return "密码错误";
        }
        session.setAttribute("user",username);
        return "ok";
    }
}
